/**
 * @author Caius
 * @description
 * @version 1.0
 * @since Created in 2025-01-20
 */

package com.itsense.stock.config;

import com.itsense.stock.pojo.vo.TaskThreadPoolInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;

@Configuration
public class TaskExecutePoolConfig {
    @Autowired
    private TaskThreadPoolInfo info;

    @Bean(name = "threadPoolTaskExecutor", destroyMethod = "shutdown")
    public ThreadPoolTaskExecutor threadPoolTaskExecutor() {
        ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
        //设置核心线程数
        executor.setCorePoolSize(info.getCorePoolSize());
        //获取最大线程数
        executor.setMaxPoolSize(info.getMaxPoolSize());
        //设置空闲时间最大存活时间
        executor.setKeepAliveSeconds(info.getKeepAliveSeconds());
        //设置任务队列长度
        executor.setQueueCapacity(info.getQueueCapacity());
        //设置参数私有化
        executor.initialize();
        return executor;
    }
}
